package com.company;

import java.io.*;

/**
 * Created by asus on 2017/8/25.
 */
public class UsingRandomAccessFile {
    static String file = "rtest.dat";
    static void display() throws IOException{
        RandomAccessFile rf = new RandomAccessFile(file,"r");
        System.out.println(rf.readUTF());
        for(int i = 0; i < 7; i++){
            System.out.println("Value" + i + ": " + rf.readDouble());
        }
        System.out.println(rf.readUTF());
        rf.close();
    }
    public static void main(String[] args) throws IOException{
        RandomAccessFile rf = new RandomAccessFile(file, "rw");
        rf.writeUTF("hh");
        for(int i = 0; i < 7; i++) {
            rf.writeDouble(i * 1.414);
        }
        rf.writeUTF("end");
        rf.close();
        display();
        rf = new RandomAccessFile(file, "rw");
        rf.seek(0*0);
        rf.writeUTF("cc");
        rf.close();
        display();

    }
}
